<!--受理详情-->
<style lang="less" scoped>
.app-class {
  .dt-head-fix {
    top: 0px;
  }
}
.dt-head{
  height:137px;
}
.add{
  height:177px;
}
</style>

<template> 
  <div class="contain">
    <!-- <app-header></app-header> -->
    <div class="dt-head" :class="{add:todolist.BillState == 'P02'}">
      <div class="dt-head-fix">
        <template v-if="todolist.BillState == 'P02'">
          <detail-header 
            :status="'请受理订单'"
            :id="todolist"></detail-header>
        </template>
        <template v-else>
          <detail-header :id="todolist"></detail-header>
        </template>
        <!--tab-->
        <!-- <div class="lltab mb10 ft14">
          <tab bar-active-color="#77babd" 
               defaultColor="#333333"
               active-color="#77babd"
               :line-width='2'>
            <tab-item selected 
              @on-item-click="tab=true">商品信息</tab-item>
            <tab-item 
              @on-item-click="tab=false">订单反馈</tab-item>
          </tab>
        </div> -->
      </div>
    </div>
   
    <div class="detail-tab-lft" v-if="tab">
      <div class="detail-supply">
        <i class="iconfont icon-supplier ft17"></i>
        {{todolist.SupplierName}}
      </div>
      <div class="detail-fedbck df-body-nopad" v-if="tododetail.length == 0">
        <voice-msg :id="todolist"></voice-msg>
      </div>

      <div class="detail-goods-list">
        <div class="displayflex list-goods-warp" v-for="item in tododetail">
          <div class="pic">
            <img :src="item.PictContent | filterImgUrl">
          </div>
          <div class="msg flex1">
            <p class="ft17">{{item.SupplierGoodsName}}</p>
            <p>{{item.SupplierGoodsSpec}}</p>
            <p>{{item.Producer}}</p>
            <em class="def-color">已出库<span class="red">{{item.SupplierArrivalQty || 0}}</span>{{item.SupplierUnit}}</em>
            <em class="def-color">共<span class="red">{{item.SupplierPoQty}}</span>{{item.SupplierUnit}}</em>
            
          </div>
        </div>
        <p class="detail-mark ft17" v-if="todolist.Memo"><em class="ft17">备注留言：</em><i class="gray">{{todolist.Memo}}</i></p>
        <div class="detail-num">
          <em v-if="todolist.CountSum>0">共{{todolist.CountSum}}种商品</em>小计:<span class="red">￥{{(amount || todolist.DetailSum) | fmoney}}</span>
        </div>
      </div>
      <div class="detail-customs">
        <p>要求到货日期：{{todolist.PlanEndDate | time}}<span v-if="todolist.BillState!='P07' && todolist.BillState!='P10'">（{{todolist.PlanEndDate | jsDateDiff}}）</span>
        </p>
        <p>下单时间：{{todolist.BillDate | timeshort}}</p>
      </div>
      <div class="detail-bottom displayflex">
        <span>合计：<em class="red">￥{{(amount || todolist.DetailSum) | fmoney}}</em></span>
        <div class="flex1 btn-grp">
          <!-- <div class="btn" @click="Share">分享</div> -->
          <div class="btn" @click="accept" v-if="todolist.BillState == 'P02'">受理</div>
        </div>
      </div>
    </div>
    <template v-if="!tab">
      <feed-back :guid="todolist.Guid" :billno='todolist.BillNo'></feed-back>
    </template>
    <!--订单分享start-->
    <mt-popup
      v-model="popupVisible"
      position="right" class="share-warp cf">
      <img src="~images/bg/arrow.png">
      <p class="tips">点击右上角进行分享</p>
    </mt-popup>
    <!--订单分享end-->
  </div>
</template>

<script>
import detailHeader from "@/components/core/header/detail_header.vue";
import feedBack from "@/components/share/billfb/billfb.vue";
import voiceMsg from "@/components/share/voiceMsg/voicemsg.vue";
import appHeader from '@/components/core/header/app_header.vue';
export default {
  name: "acceptDetail",
  components: {
    appHeader,
    detailHeader,
    feedBack,
    voiceMsg
  },
  data() {
    return {
      tab: true,
      tododetail: [],
      todolist: [],
      popupVisible: false,
      ua: navigator.userAgent.toLowerCase(),
      shares: null,
      isApp: false,
    };
  },
  computed: {
    amount() {
      var total = 0;
      for (var i = 0; i < this.tododetail.length; i++) {
        total = total + this.tododetail[i].Amount;
      }
      return total;
    },
    guid() {
      return this.$route.query.id;
    },
    userinfo() {
      return JSON.parse(localStorage.userinfo);
    }
  },
  created() {
    this.getDate();
    this.plusInit();
  },
  mounted() {
    this.$nextTick(function() {
      
    });
  },
  methods: {
    plusInit(){
      var self = this;
      if (navigator.userAgent.toLowerCase().match(/MicroMessenger/i) != "micromessenger") {
        this.isApp = true;
      }
      if(this.isApp){
        if (window.plus) {
            plusReady();
        } else {
            document.addEventListener('plusready', plusReady, false);
        }
        function plusReady() {
          self.appShareInit();
          console.log('plus已经启动并加载...')
        }
      }
    },
    appShareInit(){
      var Intent = null,
          File = null,
          Uri = null,
          main = null;
          this.updateSerivces();
          if(plus.os.name == "Android") {
            Intent = plus.android.importClass("android.content.Intent");
            File = plus.android.importClass("java.io.File");
            Uri = plus.android.importClass("android.net.Uri");
            main = plus.android.runtimeMainActivity();
          }
    },
    updateSerivces: function() {
      var self = this;
      plus.share.getServices(function(s) {
          self.shares = {};
          for (var i in s) {
              var t = s[i];
              self.shares[t.id] = t;
          }
          // plus.nativeUI.toast("获取分享服务列表成功");
      }, function(e) {
          plus.nativeUI.toast("获取分享服务列表失败：" + e.message);
      });
    },
    
    //获取详情
    getDate() {
      var self = this;
      var query = {
        Guid: this.guid
      };
      this.Ajax.post("getOrderMedPoDetailGuid", query).then(function(resp) {
        self.tododetail = resp.Datas;
      });
      this.Ajax.post("getOrderMedPoGuid", query).then(function(resp) {
        self.todolist = resp.Data;
      });
    },
    //受理操作
    accept() {
      var self = this;
      var query = {
        Guid: this.todolist.Guid,
        StaffGuid: this.userinfo.StaffID,
        StaffName: this.userinfo.Name
      };
      this.Ajax.post("OrderAudit", query).then(function(resp) {
        if (resp.IsSuccess) {
          self.MessageBox.alert("受理成功").then(action => {
            self.$router.go(-1);
          });
        } else {
          self.Toast({
            message: resp.ErrorMessage || "操作失败，请稍后重试"
          });
        }
      });
    },
    Share() {
      if(this.ua.match(/MicroMessenger/i) != "micromessenger"){
        // plus.nativeUI.toast('暂未开放');
        this.app_onMenuShareAppMessage();
      } else {
        this.popupVisible = true;
        var self = this;
        self.jWeixin.showOptionMenu();
        self.wx_onMenuShareAppMessage();
      }
    },
    wx_onMenuShareAppMessage: function() {
      var self = this;
      var url = location.href;
      url =url.substr(0, url.indexOf(location.hash)) + "static/img/logo_icon.png";
      this.jWeixin.onMenuShareAppMessage({
        title: "订单详情", // 分享标题
        desc: self.todolist.MedName+ ' 请查看订单详情，并处理订单！',
        link: "http://wxtest3.csyaoly.com/#/order/acceptSharDetail?id="+this.guid, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
        imgUrl: url, // 分享图标
        type: "", // 分享类型,music、video或link，不填默认为link
        dataUrl: "", // 如果type是music或video，则要提供数据链接，默认为空
        success: function() {
          self.$route.router.go({ path: "/order/acceptList" });
        },
        cancel: function() {
          self.$route.router.go({ path: "/order/acceptList" });
        }
      });
    },

    //APP打开分享
    app_onMenuShareAppMessage: function(){
      this.shareHref();
    },

    //分享操作
    shareAction: function(id, ex) {
      var self = this;
      var s = null;
      if (!id || !(s = self.shares[id])) {
        // plus.nativeUI.toast("无效的分享服务！");
        return;
      }
      if (s.authenticated) {
        // plus.nativeUI.toast("---已授权---");
        self.shareMessage(s, ex);
      } else {
        // plus.nativeUI.toast("---未授权---");
        s.authorize(function() {
          self.shareMessage(s, ex);
        }, function(e) {
          if(JSON.stringify(e).indexOf('未安装') > -1){
            ex = '您没有安装微信，请安装后再进行分享'
          }
          plus.nativeUI.toast("认证授权失败,ErrMsg：" + ex);
        });
      }
    },

    //发送分享消息
    shareMessage: function(s, ex) {
      // alert(1)
      var BaseUrl = window.location.href,
          BaseTitle = '订单详情',
          Desc = '请查看订单详情，并处理订单！',
          thumbs = BaseUrl.substr(0, BaseUrl.indexOf(location.hash)) + "static/img/logo_icon_44.png";  
      var msg = {
          content: Desc,
          href: BaseUrl.substr(0, BaseUrl.indexOf(location.hash)) + "/#/order/acceptSharDetail?id="+this.guid,
          title: BaseTitle,
          thumbs: [thumbs],
          pictures: [thumbs],
          extra: {
              scene: ex
          }
      };
      s.send(msg, function() {
        plus.nativeUI.toast("分享成功!");
      }, function(e) {
        // alert(JSON.stringify(e))
        var msg = '分享失败';
        if(JSON.stringify(e).indexOf('canceled') > -1){
          msg = '用户取消了分享'
        }
        plus.nativeUI.toast(msg);
      });
    },

    //分享按钮点击事件
    shareHref: function() {
      var self = this;
      var ids = [
            {
              id: "weixin", 
              ex: "WXSceneSession"  /*微信好友*/
            },
            // {
            //   id: "weixin",
            //   ex: "WXSceneTimeline" /*微信朋友圈*/
            // },
            // {
            //   id: "qq"   /*QQ好友*/
            // },
            // {
            //   id: "tencentweibo"   /*腾讯微博*/
            // },
            // {
            //   id: "sinaweibo"  /*新浪微博*/
            // }
          ],
          bts = [
            {
                title: "发送给微信好友"
            },
            // {
            //     title: "分享到微信朋友圈"
            // },
            // {
            //     title: "分享到QQ"
            // },
            // {
            //     title: "分享到腾讯微博"
            // },
            // {
            //     title: "分享到新浪微博"
            // }
          ];
      plus.nativeUI.actionSheet({
              cancel: "取消",
              buttons: bts
          },
          function(e) {
              var i = e.index;
              if (i > 0) {
                  self.shareAction(ids[i - 1].id, ids[i - 1].ex);
              }
          }
      );
    }


  },
};
</script>